var prefix="/dict/";
$(function () {
	valid();
});
$.validator.setDefaults({
    submitHandler: function() {
    	update();
    }
});
function update(){
	var d=getFormJson("signupForm");
	if (!Array.isArray(d.roleIds)) {
		var roleIdArr=[];
		roleIdArr.push(d.roleIds);
		d.roleIds=roleIdArr;
	}
    var config={
			url : prefix+"/update",
			data:d,
	}
	EasyAjax.post_json(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			parent.reLoad();
			parent.selectLoad();
			var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
			parent.layer.close(index);
		} 
	});
	
}
function valid(){
    var icon = "<i class='fa fa-times-circle'></i>";
    $("#signupForm").validate({
    	 rules:{
    		 name: {
         		 required: true,
                 maxlength: 20,
         	},
         	 value: {
                 required: true,
                 maxlength: 8,
                 isStringAndNum:true
             },
             type: {
                 required: true,
                 isStringAndNum:true
             },
             num:{
            	 number:true
             }
         },
         messages: {
         	name: {
         		required:icon + "请输标签名",
         		maxlength:icon + "标签名最多20个字符",
         	},
         	value: {
         		required:icon + "请输数据值",
         		maxlength:icon + "数据值最多8个字符",
         		isStringAndNum:icon + "只能输入英文和数字",
         	},
         	type: {
         		required:icon + "请输类型",
         		isStringAndNum:icon + "只能输入英文和数字",
             },
             num: {
            	 number:icon + "只能输入数字",
              },
             
         }
    });
}

